<?php

namespace app\airobot\controller;

use app\airobot\CommonLogic;
use app\airobot\FundConst;
use app\airobot\model\UserModel;
use think\admin\Controller;

/**
 * 超管系统-充值管理
 * Class Recharge
 * @package app\airobot\controller
 */
class Recharge extends Controller
{
    private $table = 'recharge_record';
    public $commonLogic;

    /**
     * 充值管理
     * @auth true
     */
    public function index()
    {
        $this->commonLogic = new CommonLogic();
        $this->title = '充值管理';
        $query = $this->_query($this->table);
        $where = [];
        if (!empty($_GET['user_id'])) {
            $where['user_id'] = $_GET['user_id'];
        }
        if (!empty($_GET['status'])) {
            $where['status'] = $_GET['status'];
        }
        $query->where($where);
        $query->order('id desc')->page();
    }

    protected function _index_page_filter(array &$data)
    {
        $this->commonLogic = new CommonLogic();
        $userIds = array_column($data, 'user_id');
        $userModel = new UserModel();
        $userList = $userModel->queryList([], ['field' => 'id', 'data' => $userIds], [], [], [], "", $field = "*", $order = "");
        $userMap = array_column($userList, null, 'id');
        foreach ($data as &$vo) {
            $vo['mobile'] = isset($userMap[$vo['user_id']]) ? $userMap[$vo['user_id']]['mobile'] : '';
            $vo['to_address'] = isset($userMap[$vo['user_id']]) ? $userMap[$vo['user_id']]['tron_address'] : '';
            $vo['usd_amount'] = $this->commonLogic->DealAmount($vo['usd_amount']);
        }
    }
}